package org.ims.inv.service.worklog.impl;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.ims.inv.dao.worklog.DAOWorkWeeklyLog;
import org.ims.inv.model.worklog.ModelWorkWeeklyLog;
import org.ims.inv.service.worklog.ServiceWorkWeeklyLog;

import cn.trymore.core.service.impl.ServiceGenericImpl;
import cn.trymore.core.util.UtilDate;

/**
 * Service: 工作日志 - Daily
 * 
 * @author Jeccy.Zhao
 *
 */
public class ServiceWorkWeeklyLogImpl
extends ServiceGenericImpl<ModelWorkWeeklyLog> implements ServiceWorkWeeklyLog
{
	/**
	 * The work weekly log repository.
	 */
	private DAOWorkWeeklyLog daoWorkWeeklyLog;
	
	/**
	 * The sole constructor.
	 * 
	 * @param dao
	 */
	public ServiceWorkWeeklyLogImpl(DAOWorkWeeklyLog dao)
	{
		super(dao);
		this.daoWorkWeeklyLog = dao;
	}
	
	/*
	 * (non-Javadoc)
	 * @see cn.trymore.core.service.impl.ServiceGenericImpl#getCriterias(cn.trymore.core.model.ModelBase)
	 */
	@Override
	protected DetachedCriteria getCriterias(ModelWorkWeeklyLog domain)
	{
		DetachedCriteria criteria = DetachedCriteria.forClass(ModelWorkWeeklyLog.class);
		if (domain != null)
		{
			if (domain.getLogCategory() != null)
			{
				criteria.add(Restrictions.eq("logCategory", domain.getLogCategory()));
			}
			
			if (domain.getLogOwner() != null)
			{
				criteria.createCriteria("logOwner").add(Restrictions.eq("id", domain.getLogOwner().getId()));
			}
			
			if (domain.getStartDate() != null)
			{
				criteria.add(Restrictions.sqlRestriction(
					"log_startdate = '" + (UtilDate.parseTime(domain.getStartDate(), "yyyy-MM-dd")) + "'"
				)); 
			}
			
			if (domain.getEndDate() != null)
			{
				criteria.add(Restrictions.sqlRestriction(
					"log_enddate = '" + (UtilDate.parseTime(domain.getEndDate(), "yyyy-MM-dd")) + "'"
				)); 
			}
		}
		
		return criteria;
	}

	public DAOWorkWeeklyLog getDaoWorkWeeklyLog()
	{
		return daoWorkWeeklyLog;
	}

	public void setDaoWorkWeeklyLog(DAOWorkWeeklyLog daoWorkWeeklyLog)
	{
		this.daoWorkWeeklyLog = daoWorkWeeklyLog;
	}

}
